package com.example.viewmodelstudio.lifeclcycle_processlifecycleowner;

import android.util.Log;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

/**
 * ProcessLifecycleOwner 是针对整个应用程序的监听，与Activity数量无关。
 * Lifecycle.Event.ON_CREATE只会被调用一次，Lifecycle.Event.ON_DESTROY永远不会被调用
 */
public class ApplicationObserver implements LifecycleObserver {

    private String TAG = "zdl";

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void onCreate() {
        Log.d(TAG, "===Lifecycle.Event.ON_CREATE===");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onStart() {
        Log.d(TAG, "===Lifecycle.Event.ON_START===");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void onResume() {
        Log.d(TAG, "===Lifecycle.Event.ON_RESUME===");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onPause() {
        Log.d(TAG, "===Lifecycle.Event.ON_PAUSE===");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onStop() {
        Log.d(TAG, "===Lifecycle.Event.ON_STOP===");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onDestroy() {
        Log.d(TAG, "===Lifecycle.Event.ON_DESTROY===");
    }
}
